<template>
	<view class="page_t">
		<pageheader :setting="settingdata"></pageheader>
		<go-top :scrollTop="scrollTop"></go-top>
		<view class="numbers">共{{total}}个最近通话</view>
		<view class="contents">
			<view class="personbox" v-for="(item,index) in list" :key="index">
				<image :src="item.avatar" mode="aspectFill"></image>
				<view class="person_info">
					<view class="personMain">
						<text class="personName">{{item.nickname}}</text>
						<text class="personPhone">{{item.createtime}} {{item.type==1?'供应':(item.type==2?'求购':'其他')}}来电</text>
					</view>
					<view class="personContacts" @click="dialing(item.type,item.id,item.mobile)">
						<text class="iconfont icon-dianhua1"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="not_more" v-if="list.length<1">
			<image src="../static/img/wshangji.png" mode="widthFix"></image>
			<view class="text">暂无通话</view>
		</view>
		<view class="nomore" v-if="nomore&&list.length>0">—— · 没有更多了 · ——</view>
	</view>
</template>

<script>
	var _this,$paginator;
	export default {
		data() {
			return {
				settingdata: {
					name: '最近通话',
					bgColor: '#fff',
					titleColor: '#000000',
					showNav: true,
					showTypes: 0,
					position: "recentphone"
				},
				list: [],
				nomore: false,
				// 回到头部按钮距离
				scrollTop: 0,
				// 累计通话数
				total: 0,
			}
		},
		onLoad(e) {
			_this = this
			$paginator = new _this.$paginator(_this.$api)
			_this.getdata(true)
		},
		//下拉刷新
		onPullDownRefresh() {
			$paginator = new _this.$paginator(_this.$api)
			_this.getdata(true)
		},
		onReachBottom: function() {
			$paginator.nextPager(() => {
				_this.getdata()
			})
		},
		methods: {
			getdata: function(firstLoad = false) {
				$paginator.getData("getcalllog", {
					search: _this.searchvalue
				}, (data) => {
					if (firstLoad) {
						_this.list = data.list ? data.list : []
					} else {
						_this.list = _this.list.concat(data.list)
					}
					_this.nomore = data.nomore
					_this.total = data.total
				})
			},
			//拨号并记录
			dialing(call_type,client_uid,mobile){
				_this.$api.post("calllog", {
					calllog_uid:client_uid,
					call_type:call_type
				}).then(data => {
					_this.$plug.dialing(mobile)
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page_t {
		min-height: 100vh;
		background-color: #f2f2f2;
		display: flex;
		flex-direction: column;
		align-items: center;

		.numbers {
			height: 68rpx;
			width: 100%;
			text-align: center;
			line-height: 68rpx;
			color: #B4B3B3;
			font-size: 24rpx;
		}

		.contents {
			width: 100%;
			display: flex;
			flex-direction: column;
			background-color: #fff;

			.personbox {
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: 0 51rpx 0 29rpx;

				image {
					width: 94rpx;
					height: 94rpx;
					border-radius: 50%;
				}

				.person_info {
					margin-left: 30rpx;
					padding: 35rpx 0;
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: space-between;
					border-bottom: 2rpx solid #f2f2f2;
					flex: 1;

					.personMain {
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.personName {
							color: #333333;
							font-size: 32rpx;
						}

						.personPhone {
							margin-top: 17rpx;
							color: #B6B6B6;
							font-size: 26rpx;
						}
					}

					.personContacts {
						display: flex;
						flex-direction: row;
						align-items: center;

						text {
							font-size: 40rpx;
							color: #BBBBBB;
						}
					}
				}
			}
		}
	}
</style>
